<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>


<%@page contentType="text/html" pageEncoding="UTF-8"%>


<fieldset class="form-container " style="width:80%;margin-left:5%;"> 
    <form:form id="form_782213"    method="post" action="/modele/facture/update.do" modelAttribute="modelfacture" autocomplete="on">
        <legend class="form-title"><h2>Cr&eacute;ation d'un mod&egrave;le de Facture</h2></legend>
        <h3 style="margin-bottom: 5%;margin-left: 1%">Veuillez renseigner les champs ci-dessous :</h3>
        <form:errors path="*" cssClass="errorblock" element="div"></form:errors>
            <div class="form-title">Nom de la facture </div>
        <form:input class="form-field" type="text" path="nom" tabindex="1"/>
        <div class="form-title">Code </div>
        <form:input class="form-field" type="text" path="code" tabindex="2"/>
        <div class="form-title">Type facturation </div>
        <form:select path="typeFacturation"  class="form-field">
            <form:option value="-" label="Selectionner"/>
            <form:options items="${typeFacturation}"  itemLabel="statut"/>
        </form:select>

        <form:hidden path="id"/>

        <table name = "ligneFactureModeles" id="ligneFactureModeles">
        </table>
       <textarea class="editor" name="message">${modelfacture.message}</textarea>


        <div class="submit-container" style=" clear: left;">
            <form:button class="submit-button" type="submit" >Enregistrer</form:button>
                <a href="/modele/facture/index.do" class="submit-button">Annuler</a>

            </div>
    </form:form>


</fieldset>
<script id="jsSource" type="text/javascript">
    var nbGroup = 0;
            $(function() {
            // Initialize appendGrid
            $(".editor").jqte();
                    $('#ligneFactureModeles').appendGridFacture({
            caption: '',
                    hideButtons: {
                    moveUp:true,
                            moveDown:true,
                            insert:true
                    },
                    hideRowNumColumn:true,
                    initRows: 1,
                    columns: [
                    {name: 'id', display: 'Id', type: 'hidden', ctrlCss: {width: '160px'}},
                    {name: 'positionFacture', ctrlClass: 'numeric', display: 'Ligne', type: 'number', ctrlCss: {width: '50px'}},
                    {name: 'designation', display: 'Désignation de la ligne', type: 'text', ctrlCss: {width: '160px'}},
                    {name: 'tauxBase', ctrlClass: 'numeric', display: 'Taux/Base', type: 'text', ctrlCss: {width: '50px'}},
                    {name: 'tva', ctrlClass: 'numeric', display: 'TVA', type: 'text', ctrlCss: {width: '50px'}}
                    ], idPrefix: 'ligneFactureModeles[0]'
            });
                    $('.numeric').numeric(".");
            });</script>
    
    <script id="jsSourceError" type="text/javascript">
                function reinitError() {



                var data = [
        <c:forEach var="ligne" items="${modelfacture.ligneFactureModeles}" varStatus="statusL">
            <c:choose>
                <c:when test="${statusL.index==modelfacture.ligneFactureModeles.size()-1}">
                {id:'${ligne.id}',
                        designation: '${ligne.designation}',
                        positionFacture:'${ligne.positionFacture}',
                        tauxBase: '${ligne.tauxBase}',
                        tva:'${ligne.tva}'
                }
                </c:when>
                <c:otherwise>
                {id:'${ligne.id}',
                        designation: '${ligne.designation}',
                        positionFacture:'${ligne.positionFacture}',
                        tauxBase: '${ligne.tauxBase}',
                        tva:'${ligne.tva}'
                },
                </c:otherwise>


            </c:choose>


        </c:forEach>

                ];
                        $('#ligneFactureModeles').appendGridFacture('load', data);
                }
        $(function() {
        reinitError();
                $('.numeric').numeric(".");
        });
    </script>
